home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2003 November / PCWK1103B.iso / DesignCAD 3D Max PLUS trial 30 / DATA1.CAB / Example_Files / Sample_Macros / ArcByLine.d3m < prev    next >
Encoding:
Text File  |  2003-09-29  |  1.7 KB  |  96 lines

  1. ' This program draws an arc with 4 (or 5) input points.
  2. '   Point 1 is the center of the arc
  3. '   Point 2 is the beginning point of the arc (also specifies the radius of the arc)
  4. '   Point 3 and 4 define a line that contains the ending point of the arc
  5. '      which also defines the location of the ending point
  6. '   Point 5 is an optional point for drawing a reverse arc
  7.  
  8. SETPOINT "Set points for arc: 1) Center, 2) Starting point, 3,4) Line defines the ending point, [ 5) Optional for reverse arc", 5
  9. NPTS = sys(1)
  10. IF NPTS < 4 THEN
  11.   END
  12. END IF
  13.  
  14. POINTVAL CX CY CZ 1
  15. POINTVAL SX SY SZ 2
  16. POINTVAL EX1 EY1 EZ1 3
  17. POINTVAL EX2 EY2 EZ2 4
  18.  
  19. VX = EX2 - EX1
  20. VY = EY2 - EY1
  21. VZ = EZ2 - EZ1
  22.  
  23. R2 = (SX - CX) * (SX - CX) + (SY - CY) * (SY - CY) + (SZ - CZ) * (SZ - CZ)
  24.  
  25. A = VX * VX + VY * VY + VZ * VZ
  26. B = 2 * (VX * (EX1 - CX) + VY * (EY1 - CY) + VZ * (EZ1 - CZ))
  27. C = (EX1 - CX) * (EX1 - CX) + (EY1 - CY) * (EY1 - CY) + (EZ1 - CZ) * (EZ1 - CZ) - R2
  28.  
  29. D = B * B - 4 * A * C
  30.  
  31. IF D < 0 THEN
  32.   MESSAGE "ERROR: Cannot draw an arc with the input points."
  33.   END
  34. END IF
  35.  
  36. IF NPTS < 5 THEN
  37.   A$ = "N"
  38. ELSE
  39.   A$ = "R"
  40. END IF
  41.  
  42. D = SQRT(D)
  43. A = 2 * A
  44.  
  45. T1 = (D - B) / A
  46. T2 = -(B + D) / A
  47.  
  48. X1 = EX1 + T1 * VX
  49. Y1 = EY1 + T1 * VY
  50. Z1 = EZ1 + T1 * VZ
  51.  
  52. X2 = EX1 + T2 * VX
  53. Y2 = EY1 + T2 * VY
  54. Z2 = EZ1 + T2 * VZ
  55.  
  56. DX = X2 - X1
  57. DY = Y2 - Y1
  58. DZ = Z2 - Z1
  59. D = DX * VX + DY * VY + DZ * VZ
  60.  
  61. IF D < 0 THEN
  62.   EX = X1
  63.   EY = Y1
  64.   EZ = Z1
  65. ELSE
  66.   EX = X2
  67.   EY = Y2
  68.   EZ = Z2
  69. END IF
  70.  
  71. IF A$ = "N" THEN
  72.   X1 = SX
  73.   Y1 = SY
  74.   Z1 = SZ
  75.   X2 = EX
  76.   Y2 = EY
  77.   Z2 = EZ
  78. ELSE
  79.   X2 = SX
  80.   Y2 = SY
  81.   Z2 = SZ
  82.   X1 = EX
  83.   Y1 = EY
  84.   Z1 = EZ
  85. END IF
  86.  
  87. >ARC4
  88. {
  89.   <POINTXYZ [CX, CY, CZ]
  90.   <POINTXYZ [X1, Y1, Z1]
  91.   <POINTXYZ [X2, Y2, Z2]
  92.   }
  93.  
  94.  
  95.  
  96.